<template>
    <div v-loading="loading1">
        <el-card shadow="always" class="mianbao">
            各地数据
        </el-card>
        <div class="tableSize">
        <el-table
                :data="tableData"
                stripe
                style="width: 100%">
            <el-table-column prop="id" label="编号" width="50"></el-table-column>
            <el-table-column
                    prop="time"
                    label="日期"
                    width="190">
            </el-table-column>
            <el-table-column
                    prop="email"
                    label="邮箱"
                    width="190">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="sec"
                    width="190"
                    label="描述">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">回复</el-button>
                    <el-button type="text" size="small" @click="xiangqing1(scope.row)">详情</el-button>
                </template>
            </el-table-column>
        </el-table>
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="num"
                :page-size="10"
                layout="total, prev, pager, next"
                :total="total">
        </el-pagination>
        </div>



        <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
            <el-form :model="form">
                <el-form-item label="活动名称" :label-width="formLabelWidth">
                    <el-input v-model="form.email" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="活动区域" :label-width="formLabelWidth">
                    <el-input
                            type="textarea"
                            placeholder="请输入内容"
                            v-model="form.textarea"
                            maxlength="130"
                            show-word-limit
                            autosize
                    >
                    </el-input>

                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="fasong">确 定</el-button>
            </div>
        </el-dialog>

        <el-dialog
                title="提示"
                :visible.sync="dialogVisible"
                width="30%">
            <span>{{miaoshu}}</span>
            <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
        </el-dialog>

    </div>
</template>

<script>
    export default {
        name: "GetEmail",
        data(){
            return{
                dialogVisible: false,
                loading1:false,
                tableData: [],
                dialogFormVisible: false,
                form: {
                    id:0,
                    email: '',
                    textarea:'',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: ''
                },
                formLabelWidth: '120px',
                miaoshu:'',
                currentPage1: 1,
                num:1,
                total:0
            }
        },
        created(){
            this.init();
        },
        methods:{
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.num=val;
                this.init();
            },
            xiangqing1(row){
                console.log(row);
                this.miaoshu=row.sec;
                this.dialogVisible=true
            },
            init(){

                this.$http({
                    url:'/toushu/get',
                    method:'get',
                    params:{
                        num:this.num,
                        size:10
                    }
                }).then(result=>{
                    console.log(result);
                    if(result.status==200){
                        this.tableData=result.data.list
                        this.total=result.data.total;
                    }
                })
            },
            handleClick(row) {
                this.dialogFormVisible=true;
                this.form.email=row.email;
                this.form.id=row.id;
                console.log(row);
            },
            fasong(){
                this.dialogFormVisible=false;
                this.loading1=true;
                this.loading1=false;
                this.$message({
                    type:'success',
                    message:'回复成功'
                });
                this.init();
                this.$http({
                    url:'/huifu',
                    method: 'get',
                    params:{
                        email:this.form.email,
                        context:this.form.textarea,
                        id:this.form.id
                    }
                }).then(result=>{
                    console.log(result);
                    if(result.data=="no"){
                        this.$message({
                            type:'error',
                            message:'没有对应的值'
                        })
                    }
                })
            }
        }
    }
</script>

<style scoped>
.tableSize{
    width: 60%;
    margin-top: 5%;
    margin-left: 20%;
}
.mianbao {
    text-align: center;
}
</style>
